#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;

int n;
int a[MAXN];
ll dp[MAXN], dp2[MAXN];

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    a[n+1] = a[1];

    dp[1] = a[1];

    for (int i = 2; i <= n; i++) {
        dp[i] = min(dp[i-2]+a[i-1], dp[i-1]+a[i]);
    }
    // cout << dp[n] << endl;

    dp2[2] = a[2];
    for (int i = 3; i <= n+1; i++) {
        dp2[i] = min(dp2[i-2]+a[i-1], dp2[i-1]+a[i]);
    }

    cout << min(dp[n], dp2[n+1]) << endl;
    return 0;
}